#!/bin/bash

while ! [ -e os3jslib ]
do
	cd ..
done

CSSFILE=/tmp/css.out.lst
JSFILE=/tmp/js.out.lst

cat /dev/null > $JSFILE
cat /dev/null > $CSSFILE

find . -name "*.js" | while read infile
do
	if [[ $infile == *.comp.js* ]]
	then
		continue
	fi

	if [[ $infile == *docs/build* ]]
	then
		continue
	fi

	outfile=$(echo $infile | sed "s/.js$/.comp.js/")
	if [ $infile -nt $outfile ]
	then
		echo $infile >> $JSFILE

		echo "Compressing: $infile"
		jscompress "$infile" "$outfile"
	fi

done

#echo "Building JS"
#at $JSFILE | xargs jscompressall

exit

find . -name "*.css" | while read infile
do
	if [[ $infile == *.comp.css* ]]
	then
		continue
	fi

	if [[ $infile == *docs/build* ]]
	then
		continue
	fi

	outfile=$(echo $infile | sed "s/.css$/.comp.css/")
	if [ $infile -nt $outfile ]
	then
		echo $infile >> $CSSFILE
	fi
done

echo "Building CSS"
cat $JSFILE | xargs csscompressall
